const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: "",
    viplist: ["一级会员", "二级会员", "三级会员", "四级会员", "五级会员"],
    status: false,
    vipclick: false,
    otherclick:false,
    page: 1,
    memberList: [],
    grade:0,
    rebateMoney:"",//返利总额
    buyMoney:"",//购买总额
    sonMember:"",//下级会员
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
      this.getMemberList(1);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
     this.setData({
       memberList:[]
     });
     this.getMemberList(1);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },

  Tabletarget: function(e) {
    var that = this;
    console.log(e)
    if (e.currentTarget.dataset.current==0){
      that.setData({
        vipclick: true,
        otherclick:false
      })
    }
    if (e.currentTarget.dataset.current == 1) {
      that.setData({
        vipclick:false,
        otherclick: true
      })
    }
    if (this.data.currentTab === e.currentTarget.dataset.current) {
      if (this.data.status) {
        that.setData({
          status: false,
          vipclick: false,
          otherclick: false
        })
      } else {
        that.setData({
          status: true
        })
      }
      return false;
    } else {
      that.setData({
        currentTab: e.currentTarget.dataset.current,
        status: true
      })
    }
  },
  onhide: function() {
    this.setData({
      status: false,
      vipclick: false,
      otherclick: false
    })
  },
  /**
     * 获取商品列表
     */
  getMemberList: function (page) {
    var that = this;
    wx.request({
      url: app.globalData.server + "/merchantApplet/memberList",
      data: {
        page: page,
        orgId: wx.getStorageSync('orgId'),
        grade: that.data.grade,
        rebateMoney: that.data.rebateMoney,//返利总额
        buyMoney: that.data.buyMoney,//购买总额
        sonMember: that.data.sonMember,//下级会员
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.code != '000000') {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 1000
          })
        } else {
          var oldmemberList = that.data.memberList;
          oldmemberList = oldmemberList.concat(res.data.data);
          that.setData({
            memberList: oldmemberList,
            page: that.data.page + 1
          });
          wx.stopPullDownRefresh();//停止下拉刷新
        }
      }
    })
  },
  /**
   * 点击进行搜索
   */
  search: function () {
    console.log("进行搜索");
  }

})